home *** CD-ROM | disk | FTP | other *** search
- Path: erich.triumf.ca!bennett
- From: bennett@erich.triumf.ca (P.Bennett)
- Newsgroups: comp.lang.c
- Subject: Re: switching base 10 to hex
- Date: 3 Apr 1996 10:12 PST
- Organization: TRIUMF: Tri-University Meson Facility
- Distribution: world
- Message-ID: <3APR199610123176@erich.triumf.ca>
- References: <4ju6a9$kl6@coranto.ucs.mun.ca>
- NNTP-Posting-Host: ftp.triumf.ca
- News-Software: VAX/VMS VNEWS 1.50
-
- In article <4ju6a9$kl6@coranto.ucs.mun.ca>, jdeeley@calvin.stemnet.nf.ca (J.Deeley) writes...
-
- >I am teaching myself to program in C using a book that came with my
- >compiler. In the book I just ran into a small section which deals with
- >switching base 10 numbers to base two numbers (no problems there, thats
- >easy) and also switching base 10 numbers to hexidecimal (base 16).
- >
- >Agh! My book does a lousy job of explaining how that works, and one of
- >the alternative explanations I found on the net does no better. Can
- >someone give me a good, simple way to get a hexadecimal number from a
- >normal number? Like the number 400 for instance? Go slow...
-
- Within your program, all integers are stored and manipulated as binary
- numbers.
-
- If you want to print a number in decimal, you use:
- printf("%d", num);
- To print in hex, use:
- printf(%x", num);
- or, in octal:
- printf("%o", num);
-
- Look up the format specifiers for printf()....
-
-
- Peter Bennett VE7CEI | Vessels shall be deemed to be in sight
- Internet: bennett@triumf.ca | of one another only when one can be
- Packet: ve7cei@ve7kit.#vanc.bc.ca | observed visually from the other
- TRIUMF, Vancouver, B.C., Canada | ColRegs 3(k)
- GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
- or: ftp://ftp-i2.informatik.rwth-aachen.de/pub/arnd/GPS/peter/index.html
-
-